<?php
	class LoginControl{
	
		public $session_started;
		
		function __construct(){
			$this->session_started = false;
		}
	
		public function login($usuario, $clave){
			$usuario = mysql_real_escape_string($usuario);
		
			$query = "SELECT id, rol FROM usuarios 
				WHERE usuario = '$usuario' AND clave = MD5('$clave')";
				
			$res = mysql_query($query) or die("Error SQL");
			$fila = mysql_fetch_assoc($res);
			
			if(!$fila)
				return false;
				
			$id = mysql_insert_id();
			$this->session_start();
			$_SESSION['usuario'] = $usuario;
			$_SESSION['id'] = $fila['id'];
                        $_SESSION['rol'] = $fila['rol'];
			
			return true;
		
		}
		
		private function session_start(){
			if(!$this->session_started)
				session_start();
		}
		
		public function is_logged_in(){
			$this->session_start();
			
			if(isset($_SESSION['id']))
				return true;
			else
				return false;
		}

	
	
	
	}
	
	
?>